"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_api = require("../../utils/api.js");
const _sfc_main = {
  __name: "recommend",
  setup(__props) {
    const recommendList = common_vendor.ref([]);
    const loading = common_vendor.ref(false);
    const loadRecommendations = async () => {
      loading.value = true;
      try {
        const res = await utils_api.courseApi.getRecommendCourses();
        if (res.code === 0 && res.data) {
          recommendList.value = res.data;
        }
      } catch (error) {
        console.error("获取推荐失败:", error);
        common_vendor.index.showToast({
          title: "获取推荐失败",
          icon: "none"
        });
      } finally {
        loading.value = false;
      }
    };
    const switchTab = (tab) => {
      if (tab === "all") {
        common_vendor.index.switchTab({
          url: "/pages/course/course"
        });
      }
    };
    const goToCourseDetail = (courseId) => {
      common_vendor.index.navigateTo({
        url: `/pages/course/detail?id=${courseId}`
      });
    };
    common_vendor.onMounted(() => {
      loadRecommendations();
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(($event) => switchTab("all")),
        b: loading.value
      }, loading.value ? {} : common_vendor.e({
        c: common_vendor.f(recommendList.value, (course, k0, i0) => {
          return {
            a: course.image || "/static/course/default.jpg",
            b: common_vendor.t(course.title),
            c: common_vendor.t(course.description),
            d: course.id,
            e: common_vendor.o(($event) => goToCourseDetail(course.id), course.id)
          };
        }),
        d: recommendList.value.length === 0
      }, recommendList.value.length === 0 ? {} : {}));
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-72ed54cd"]]);
wx.createPage(MiniProgramPage);
